<div class="layui-card">
    <div class="layui-card-header">
        <div class="layui-btn-group">
            <a class="layui-btn layui-btn-sm" href="<?php echo \yii\helpers\Url::to(['create']) ?>" ><i class="layui-icon layui-icon-add-1"></i>添加权限</a>
        </div>
    </div>
    <div class="layui-card-body">
        <table class="layui-table">
            <thead>
            <tr>
                <th><input type="checkbox" lay-skin="primary"></th>
                <th>名称</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($data as $d){ ?>
                <tr>
                    <td><input type="checkbox" lay-skin="primary"></td>
                    <td><i class="layui-icon layui-icon-layer"></i> <?php echo $d['description']; ?>（<?php echo $d['name']; ?>）</td>
                    <td><?php echo date('Y-m-d H:i',$d['created_at']); ?></td>
                    <td>
                        <a href="<?php echo \yii\helpers\Url::to(['edit','name'=>$d['name']]); ?>" class="layui-btn layui-btn-xs"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                        <a data-url="<?php echo \yii\helpers\Url::to(['destroy','name'=>$d['name']]); ?>" class="layui-btn layui-btn-xs layui-btn-danger option-destroy"><i class="layui-icon layui-icon-delete"></i>删除</a>
                    </td>
                </tr>
                <?php if (isset($d['child'])&&!empty($d['child'])){ ?>
                    <?php foreach ($d['child'] as $c){ ?>
                        <tr>
                            <td><input type="checkbox" lay-skin="primary"></td>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┗━━<i class="layui-icon layui-icon-file"></i> <?php echo $c['description']; ?>（<?php echo $c['name']; ?>）</td>
                            <td><?php echo date('Y-m-d H:i',$c['created_at']); ?></td>
                            <td>
                                <a href="<?php echo \yii\helpers\Url::to(['edit','name'=>$c['name']]); ?>" class="layui-btn layui-btn-xs"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                                <a data-url="<?php echo \yii\helpers\Url::to(['destroy','name'=>$c['name']]); ?>" class="layui-btn layui-btn-xs layui-btn-danger option-destroy"><i class="layui-icon layui-icon-delete"></i>删除</a>
                            </td>
                        </tr>
                    <?php } ?>
                <?php } ?>
            <?php } ?>
            </tbody>
        </table>
    </div>
</div>


<?php

$js = <<<JS
    layui.use(['form','element','table', 'layer'],function() {
        var form = layui.form;  
        var element = layui.element;  
        var table = layui.table;  
        var layer = layui.layer;  
        
        $(".option-destroy").click(function() {
            var url = $(this).data('url');
            layer.confirm('确认删除吗？',function() {
                $.post(url,{},function(res) {
                    layer.closeAll();
                    layer.msg(res.msg,{},function() {
                        if (res.code==0){
                            location.reload()
                        }   
                    })
                })
            })
        })
        
    });
JS;
$this->registerJs($js);
